Utilities Functions¶
-
pysimrel.utilities.get_cov(rel_pos, rsq, kappa, lmd, random_seed=None)[source]¶ Compute Covariances
Compute covariances at the position specified in
rel_posrecursively using the functionsample_covsatisfying thersqand the eigen values inkappaandlmd.Parameters: - rel_pos (list) – position of relevant components
- rsq (list) – A list of coefficient of determination
- kappa (list) – A list of eigenvalues related to response variables
- lmd (list) – A list of eigenvalues related to predictor variables
- random_seed (int) – An integer for random state
Returns: A matrix of dimension equals to the length of
kappaby length oflmdwith computed covariances at the position specified inrel_pos.Return type: np.array
-
pysimrel.utilities.get_eigen(rate, nvar, min_value=0.0001)[source]¶ Compute eigen values using exponential decay function.
\[\lambda_i = \text{exp}^{-\gamma(i-1)}\]Parameters: - rate – rate of exponential decay factor
- nvar – Number of variables (number of eigenvalues to compute)
- min_value – Lower limit for smallest eigenvalue
Returns: A list of eigenvalues
-
pysimrel.utilities.get_relpred(n_pred, n_relpred, pos_relcomp, random_state=None)[source]¶ Identify relevant predictors through sampling
Get relevant and irrelevant position of predictor variables. The irrelevant components index are the one which are not in
pos_relcomp. The number of extra components are defined inn_relpred.Parameters: - n_pred (int) – Number of predictor variables
- n_relpred (list) – List of number of predictors relevant for each response
- pos_relcomp (list) – List of List containing the position index of relevant components
- random_state (int) – An integer for random state
Returns: A dictionary with relevant and irrelevant position index of predictors
Return type: dict
-
pysimrel.utilities.get_rotate(mat, pred_pos, random_state=None)[source]¶ Fill up a block of matrix
matbased on position index inpred_pos. The block will be an orthogonal rotation matrix.Parameters: - mat (np.array) – A matrix possibly a square matrix as covariance
- pred_pos (list) – A list of position index for the block rotation
- random_state (int) – An integer for random state to control randomness
Returns: A matrix of same size as
matbut filled with an orthogonal blockReturn type: np.array
-
pysimrel.utilities.get_rotation(rel_irrel_pred)[source]¶ Create orthogonal rotation matrix
Creates an orthogonal rotation matrix from dictionary of relevant and irrelevant positions using get_rotate function.
Parameters: rel_irrel_pred (dict) – A dictionary of relevant and irrelevant position (possibly obtained from the function get_relpred. Returns: An orthogonal rotation matrix Return type: np.array
-
pysimrel.utilities.parse_param(parm: Union[str, int, None])[source]¶ Parse the parameters from string to a nested list
Parameters: parm (str, int) – Either integer, float (in some cases) or mostly string Returns: A nested list of parsed parameters Return type: list
-
pysimrel.utilities.sample_cov(lmd, rsq, pos, kappa, alpha_)[source]¶ Compute covariance satisfying given parameters
Compute covariance from a sample of uniform distribution satisfying rsq, a set of lmd and kappa
Parameters: - lmd (set or list) – A set of eigenvalue of predictors at position specified by
pos. - rsq (float) – Coefficient of determination
- pos (list) – Position index of in which covariance need to be non-zero
- kappa (list) – Eigenvalue corresponding to response (univariate) or response component (multivariate)
- alpha – A sample from univariate distribution between -1 and 1
Returns: An array of computed covariances of length equals to
lmd.Return type: np.array
- lmd (set or list) – A set of eigenvalue of predictors at position specified by
-
pysimrel.utilities.sample_extra_pos(rs, n_extra_pos, extra_pos, irrel_pos)[source]¶ Sample Extra Position Required
Sample position index of extra relevant predictors from irrelevant predictors in
irrel_pos.Parameters: - rs (int) – A numpy RandomSeed object
- n_extra_pos (int) – An integer for number of extra position index to sample
- extra_pos (list) – A list container for collecting extra relevant components
- irrel_pos (list) – A list or set of irrelevant position indices
Returns: a list of relevant and irrelevant position indices
Return type: list